<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" class="data-form">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="会员名" clearable style="width: 200px"></el-input>
      </el-form-item>
      <el-form-item>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        prop="addTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="会员名">
      </el-table-column>
      <el-table-column
        prop="mobile"
        header-align="center"
        align="center"
        label="手机号码">
      </el-table-column>
      <el-table-column
        prop="fromUserId"
        header-align="center"
        align="center"
        label="区域">
        <template  slot-scope="scope">
          <span>{{scope.row.area + ' ' + scope.row.city + ' ' + scope.row.province}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="loginCount"
        header-align="center"
        align="center"
        label="登录次数">
      </el-table-column>
      <el-table-column
        prop="lastLoginDate"
        header-align="center"
        align="center"
        label="最后登录时间">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="激活状态">
        <template  slot-scope="scope">
          <el-switch
            style="display: block"
            v-model="scope.row.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value= 0
            :inactive-value= 1
            active-text="是"
            inactive-text="否"
            @change="statusChange(dataList[scope.$index].id, scope.row.status)">
          </el-switch>
          <!--<el-tag type="success" v-if="scope.row.status === 0">正常</el-tag>
          <el-tag type="danger" v-else="">锁定</el-tag>
          &lt;!&ndash;<span>{{scope.row.status === 0 ? '正常':'锁定'}}</span>&ndash;&gt;-->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        keywords: ''
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false
    }
  },
  components: {
  },
  activated () {
    this.getDataList()
  },
  methods: {
    // 改变启用状态
    statusChange (id, status) {
      console.log(id)
      debugger
      this.$confirm(status === 0 ? '确定激活状态 ？' : '确定禁用状态 ？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl(`/member/user/modifyById`),
          method: 'post',
          data: this.$http.adornData({
            'id': id,
            'status': status
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1000,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      })
      this.getDataList()
    },
    getDataList () {
      console.log(this.memberType)
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/member/user/queryOperatorList'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'keywords': this.dataForm.keywords
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list
          this.totalPage = data.data.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
      // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
      // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    }
  }
}
</script>
<style>
  .characters{
    width:300px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  .data-form .el-select{
    width: 110px;
  }
  .data-form .el-input{
    width: 110px;
  }
</style>
